<!-- HTML header for doxygen 1.9.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CMSIS-Core (Cortex-M): Using CMSIS-Core</title>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="tabs.js"></script>
<script type="text/javascript" src="footer.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/javascript" src="darkmode_toggle.js"></script>
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
<link href="extra_navtree.css" rel="stylesheet" type="text/css"/>
<link href="extra_search.css" rel="stylesheet" type="text/css"/>
<link href="extra_tabs.css" rel="stylesheet" type="text/css"/>
<link href="version.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../version.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 55px;">
  <td id="projectlogo" style="padding: 1.5em;"><img alt="Logo" src="cmsis_logo_white_small.png"/></td>
  <td style="padding-left: 1em; padding-bottom: 1em;padding-top: 1em;">
   <div id="projectname">CMSIS-Core (Cortex-M)
   &#160;<span id="projectnumber"><script type="text/javascript">
     <!--
     writeHeader.call(this);
     writeVersionDropdown.call(this, "CMSIS-Core (Cortex-M)");
     //-->
    </script>
   </span>
   </div>
   <div id="projectbrief">CMSIS-Core support for Cortex-M processor-based devices</div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
  <!--END !PROJECT_NAME-->
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
  <ul class="tablist">
    <script type="text/javascript">
      writeComponentTabs.call(this);
    </script>
  </ul>
</div>
<script type="text/javascript">
  writeSubComponentTabs.call(this);
</script>
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('using_pg.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">Using CMSIS-Core </div></div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#using_packs">Usage in CMSIS-Packs</a></li>
<li class="level1"><a href="#usage_examples">Usage Examples</a><ul><li class="level2"><a href="#using_basic">Basic CMSIS Example</a></li>
<li class="level2"><a href="#using_vtor">Using Interrupt Vector Remap</a></li>
<li class="level2"><a href="#using_arm">Use generic Arm Devices</a></li>
<li class="level2"><a href="#using_ARM_Lib_sec">Create generic libraries</a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><p><a class="anchor" id="md_src_using"></a></p>
<p>To use the CMSIS-Core (Cortex-M) in an embedded software project at the following <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a> need to be added to the application:</p>
<ul>
<li><a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> with reset handler and exception vectors.</li>
<li><a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> with general device configuration (i.e. for clock and BUS setup).</li>
<li><a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> gives access to processor core and all peripherals.</li>
</ul>
<div class="image">
<img src="CMSIS_CORE_Files_USER.png" alt=""/>
<div class="caption">
Using CMSIS-Core (Cortex-M) in a project</div></div>
    <p>The <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> is executed after reset and calls <code><a class="el" href="group__system__init__gr.html#ga93f514700ccf00d08dbdcff7f1224eb2" title="Function to Initialize the system.">SystemInit()</a></code> in the reset hander. After the system initialization the control is transferred to the C/C++ run-time library which performs initialization and calls the <code>main</code> function in the user code. In addition the <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> contains all exception and interrupt vectors and implements a default function for every interrupt. It may also contain stack and heap configurations for the user application.</p>
<p>The <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> performs the setup for the processor clock. The variable <a class="el" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> indicates the CPU clock speed. In addition the file may contain functions for the memory BUS setup and clock re-configuration.</p>
<blockquote class="doxtable">
<p>&zwj;<b>Note</b></p><ul>
<li>The files <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> and <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> may require application specific adaptations and therefore should be copied into the application project folder prior configuration. </li>
</ul>
</blockquote>
<p>The <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> provides access to the following device-specific functionalities:</p>
<ul>
<li><a class="el" href="group__peripheral__gr.html">Peripheral Access</a> provides a standardized register layout for all peripherals. Optionally functions for device-specific peripherals may be available.</li>
<li><a class="el" href="group__NVIC__gr.html">Interrupts and Exceptions (NVIC)</a> can be accessed with standardized symbols and functions for the Nested Interrupt Vector Controller (NVIC) are provided.</li>
<li><a class="el" href="group__intrinsic__CPU__gr.html">Intrinsic Functions for CPU Instructions</a> allow to access special instructions, for example for activating sleep mode or the NOP instruction.</li>
<li><a class="el" href="group__intrinsic__SIMD__gr.html">Intrinsic Functions for SIMD Instructions</a> provide access to the DSP-oriented instructions.</li>
<li><a class="el" href="group__SysTick__gr.html">Systick Timer (SYSTICK)</a> function to configure and start a periodic timer interrupt.</li>
<li><a class="el" href="group__ITM__Debug__gr.html">Debug Access</a> are functions that allow printf-style I/O via the CoreSight Debug Unit and ITM communication.</li>
</ul>
<h1><a class="anchor" id="using_packs"></a>
Usage in CMSIS-Packs</h1>
<p>The easiest way to use CMSIS-Core in a project is with CMSIS Packs.</p>
<p>The <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a> are typically provided in a <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/cp_PackTutorial.html#createPack_DFP">CMSIS Device Family Pack (DFP)</a> that is maintained by the chip vendor for the target device family. The list of public CMSIS packs (including DFPs) can be found at <a href="https://www.keil.arm.com/packs/">keil.arm.com/packs</a>.</p>
<p>A Device Family Pack (DFP) usually has a requirement for using the <b>CMSIS:CORE</b> component from the <a href="../General/cmsis_pack.html">CMSIS Software pack</a> that contains the <a class="el" href="cmsis_core_files.html#cmsis_standard_files">CMSIS-Core Standard Files</a>. In such case the CMSIS Software pack needs to be installed as well.</p>
<p>The files <a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> and <a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> are typically provided in the DFP as part of <b>Device</b> class in the <b>Startup</b> group and are defined as configuration files, meaning they are copied from the pack into a project folder and can be modifed there if necessary.</p>
<p>The use of <a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> can be abstracted with the <code>#define CMSIS_header_file</code> provided in <a href="https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/cp_Packs.html#cp_RTECompH">RTE_Components.h</a>. This allows to have uniform include code in the application independent of the target device.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span>                      <span class="comment">// include information about project configuration</span></div>
<div class="line"><span class="preprocessor">#include CMSIS_device_header                     </span><span class="comment">// include &lt;Device&gt;.h file</span></div>
</div><!-- fragment --><p>Thereafter, the functions described under <a href="modules.html">API Reference</a> can be used in the application.</p>
<p>For example, the following files are provided by the STM32F10x device family pack:</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadLeft">File   </th><th class="markdownTableHeadLeft">Description    </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">".\Device\Source\ARM\startup_stm32f10x_cl.s"   </td><td class="markdownTableBodyLeft"><a class="el" href="startup_c_pg.html">Startup File startup_&lt;Device&gt;.c</a> for the STM32F10x device variants    </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyLeft">".\Device\Source\system_stmf10x.c"   </td><td class="markdownTableBodyLeft"><a class="el" href="system_c_pg.html">System Configuration Files system_&lt;Device&gt;.c and system_&lt;Device&gt;.h</a> for the STM32F10x device families    </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyLeft">".\Device\Include\stm32f10x.h"   </td><td class="markdownTableBodyLeft"><a class="el" href="device_h_pg.html">Device Header File &lt;Device.h&gt;</a> for the STM32F10x device families   </td></tr>
</table>
<p><a class="el" href="cmsis_files_dfps.html">Delivery in CMSIS-Packs</a> provides more information on how CMSIS-Core files can be delivered in CMSIS Packs.</p>
<h1><a class="anchor" id="usage_examples"></a>
Usage Examples</h1>
<p><b>Examples</b></p>
<ul>
<li><a class="el" href="using_pg.html#using_basic">Basic CMSIS Example</a> is a simple example that shows the usage of the CMSIS layer.</li>
<li><a class="el" href="using_pg.html#using_vtor">Using Interrupt Vector Remap</a> shows how to remap the interrupt vector table.</li>
<li><a class="el" href="using_pg.html#using_arm">Use generic Arm Devices</a> explains how to use CMSIS-Core (Cortex-M) for Arm processors.</li>
<li><a class="el" href="using_pg.html#using_ARM_Lib_sec">Create generic libraries</a> explains how to create libraries that support various Cortex-M cores.</li>
</ul>
<p>Also see <a class="el" href="using_TrustZone_pg.html">Using TrustZone for Armv8-M</a> that details CMSIS-Core support for Arm TrusZone operation on Cortex-M.</p>
<h2><a class="anchor" id="using_basic"></a>
Basic CMSIS Example</h2>
<p>A typical example for using the CMSIS layer is provided below. The example is based on a STM32F10x Device.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stm32f10x.h&gt;</span>                           <span class="comment">// File name depends on device used</span></div>
<div class="line"> </div>
<div class="line">uint32_t <span class="keyword">volatile</span> msTicks;                       <span class="comment">// Counter for millisecond Interval</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> SysTick_Handler (<span class="keywordtype">void</span>) {                    <span class="comment">// SysTick Interrupt Handler</span></div>
<div class="line">  msTicks++;                                     <span class="comment">// Increment Counter</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> WaitForTick (<span class="keywordtype">void</span>)  {</div>
<div class="line">  uint32_t curTicks;</div>
<div class="line"> </div>
<div class="line">  curTicks = msTicks;                            <span class="comment">// Save Current SysTick Value</span></div>
<div class="line">  <span class="keywordflow">while</span> (msTicks == curTicks)  {                 <span class="comment">// Wait for next SysTick Interrupt</span></div>
<div class="line">    <a class="code hl_function" href="group__intrinsic__CPU__gr.html#gad3efec76c3bfa2b8528ded530386c563">__WFE</a> ();                                    <span class="comment">// Power-Down until next Event/Interrupt</span></div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> TIM1_UP_IRQHandler (<span class="keywordtype">void</span>) {                 <span class="comment">// Timer Interrupt Handler</span></div>
<div class="line">  ;                                              <span class="comment">// Add user code here</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> timer1_init(<span class="keywordtype">int</span> frequency) {                <span class="comment">// Set up Timer (device specific)</span></div>
<div class="line">  <a class="code hl_function" href="group__NVIC__gr.html#ga5bb7f43ad92937c039dee3d36c3c2798">NVIC_SetPriority</a> (TIM1_UP_IRQn, 1);            <span class="comment">// Set Timer priority</span></div>
<div class="line">  <a class="code hl_function" href="group__NVIC__gr.html#ga530ad9fda2ed1c8b70e439ecfe80591f">NVIC_EnableIRQ</a> (TIM1_UP_IRQn);                 <span class="comment">// Enable Timer Interrupt</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> Device_Initialization (<span class="keywordtype">void</span>)  {             <span class="comment">// Configure &amp; Initialize MCU</span></div>
<div class="line">  <span class="keywordflow">if</span> (<a class="code hl_function" href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a> (<a class="code hl_variable" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> / 1000)) { <span class="comment">// SysTick 1mSec</span></div>
<div class="line">       : <span class="comment">// Handle Error </span></div>
<div class="line">  }</div>
<div class="line">  timer1_init ();                                <span class="comment">// setup device-specific timer</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">// The processor clock is initialized by CMSIS startup + system file</span></div>
<div class="line"><span class="keywordtype">void</span> main (<span class="keywordtype">void</span>) {                               <span class="comment">// user application starts here</span></div>
<div class="line">  Device_Initialization ();                      <span class="comment">// Configure &amp; Initialize MCU</span></div>
<div class="line">  <span class="keywordflow">while</span> (1)  {                                   <span class="comment">// Endless Loop (the Super-Loop)</span></div>
<div class="line">    <a class="code hl_function" href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a> ();                            <span class="comment">// Disable all interrupts</span></div>
<div class="line">    Get_InputValues ();                          <span class="comment">// Read Values</span></div>
<div class="line">    <a class="code hl_function" href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a> ();                             <span class="comment">// Enable all interrupts </span></div>
<div class="line">    Calculation_Response ();                     <span class="comment">// Calculate Results</span></div>
<div class="line">    Output_Response ();                          <span class="comment">// Output Results</span></div>
<div class="line">    WaitForTick ();                              <span class="comment">// Synchronize to SysTick Timer</span></div>
<div class="line">  }</div>
<div class="line">}</div>
<div class="ttc" id="agroup__Core__Register__gr_html_ga0f98dfbd252b89d12564472dbeba9c27"><div class="ttname"><a href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a></div><div class="ttdeci">void __enable_irq(void)</div><div class="ttdoc">Globally enables interrupts and configurable fault handlers.</div></div>
<div class="ttc" id="agroup__Core__Register__gr_html_gaeb8e5f7564a8ea23678fe3c987b04013"><div class="ttname"><a href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a></div><div class="ttdeci">void __disable_irq(void)</div><div class="ttdoc">Globally disables interrupts and configurable fault handlers.</div></div>
<div class="ttc" id="agroup__NVIC__gr_html_ga530ad9fda2ed1c8b70e439ecfe80591f"><div class="ttname"><a href="group__NVIC__gr.html#ga530ad9fda2ed1c8b70e439ecfe80591f">NVIC_EnableIRQ</a></div><div class="ttdeci">void NVIC_EnableIRQ(IRQn_Type IRQn)</div><div class="ttdoc">Enable a device specific interrupt.</div></div>
<div class="ttc" id="agroup__NVIC__gr_html_ga5bb7f43ad92937c039dee3d36c3c2798"><div class="ttname"><a href="group__NVIC__gr.html#ga5bb7f43ad92937c039dee3d36c3c2798">NVIC_SetPriority</a></div><div class="ttdeci">void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)</div><div class="ttdoc">Set the priority for an interrupt.</div></div>
<div class="ttc" id="agroup__SysTick__gr_html_gabe47de40e9b0ad465b752297a9d9f427"><div class="ttname"><a href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a></div><div class="ttdeci">uint32_t SysTick_Config(uint32_t ticks)</div><div class="ttdoc">System Tick Timer Configuration.</div></div>
<div class="ttc" id="agroup__intrinsic__CPU__gr_html_gad3efec76c3bfa2b8528ded530386c563"><div class="ttname"><a href="group__intrinsic__CPU__gr.html#gad3efec76c3bfa2b8528ded530386c563">__WFE</a></div><div class="ttdeci">void __WFE(void)</div><div class="ttdoc">Wait For Event.</div></div>
<div class="ttc" id="agroup__system__init__gr_html_gaa3cd3e43291e81e795d642b79b6088e6"><div class="ttname"><a href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a></div><div class="ttdeci">uint32_t SystemCoreClock</div><div class="ttdoc">Variable to hold the system core clock value.</div><div class="ttdef"><b>Definition:</b> ref_system_init.txt:68</div></div>
</div><!-- fragment --><h2><a class="anchor" id="using_vtor"></a>
Using Interrupt Vector Remap</h2>
<p>Most Cortex-M processors provide VTOR register for remapping interrupt vectors. The following example shows a typical use case where the interrupt vectors are copied to RAM and the <code>SysTick_Handler</code> is replaced.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;ARMCM3.h&quot;</span>                     <span class="comment">// Device header</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define VECTORTABLE_SIZE        (240)    </span><span class="comment">/* size of the used vector tables    */</span><span class="preprocessor"></span></div>
<div class="line">                                         <span class="comment">/* see startup file startup_ARMCM3.c */</span></div>
<div class="line"><span class="preprocessor">#define VECTORTABLE_ALIGNMENT   (0x100U) </span><span class="comment">/* 16 Cortex + 32 ARMCM3 = 48 words  */</span><span class="preprocessor"></span></div>
<div class="line">                                         <span class="comment">/* next power of 2 = 256             */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* externals from startup_ARMCM3.c */</span></div>
<div class="line"><span class="keyword">extern</span> uint32_t <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[VECTORTABLE_SIZE];        <span class="comment">/* vector table ROM  */</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/* new vector table in RAM, same size as vector table in ROM */</span></div>
<div class="line">uint32_t vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) ));</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  SysTick_Handler</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keyword">volatile</span> uint32_t msTicks = 0;                        <span class="comment">/* counts 1ms timeTicks */</span></div>
<div class="line"><span class="keywordtype">void</span> SysTick_Handler(<span class="keywordtype">void</span>) {</div>
<div class="line">  msTicks++;                                             <span class="comment">/* increment counter */</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  SysTick_Handler (RAM)</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keyword">volatile</span> uint32_t msTicks_RAM = 0;                    <span class="comment">/* counts 1ms timeTicks */</span></div>
<div class="line"><span class="keywordtype">void</span> SysTick_Handler_RAM(<span class="keywordtype">void</span>) {</div>
<div class="line">  msTicks_RAM++;                                      <span class="comment">/* increment counter */</span></div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">  MAIN function</span></div>
<div class="line"><span class="comment"> *----------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line">  uint32_t i;</div>
<div class="line">   </div>
<div class="line">  <span class="keywordflow">for</span> (i = 0; i &lt; VECTORTABLE_SIZE; i++) {</div>
<div class="line">    vectorTable_RAM[i] = <a class="code hl_define" href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a>[i];       <span class="comment">/* copy vector table to RAM */</span></div>
<div class="line">  }</div>
<div class="line">                                                   <span class="comment">/* replace SysTick Handler */</span></div>
<div class="line">  vectorTable_RAM[<a class="code hl_enumvalue" href="group__NVIC__gr.html#gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7">SysTick_IRQn</a> + 16] = (uint32_t)SysTick_Handler_RAM;</div>
<div class="line">  </div>
<div class="line">  <span class="comment">/* relocate vector table */</span> </div>
<div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#gaeb8e5f7564a8ea23678fe3c987b04013">__disable_irq</a>();</div>
<div class="line">    SCB-&gt;VTOR = (uint32_t)&amp;vectorTable_RAM;</div>
<div class="line">  <a class="code hl_function" href="group__intrinsic__CPU__gr.html#gacb2a8ca6eae1ba4b31161578b720c199">__DSB</a>();</div>
<div class="line">  <a class="code hl_function" href="group__Core__Register__gr.html#ga0f98dfbd252b89d12564472dbeba9c27">__enable_irq</a>();</div>
<div class="line"> </div>
<div class="line">  <a class="code hl_function" href="group__system__init__gr.html#gae0c36a9591fe6e9c45ecb21a794f0f0f">SystemCoreClockUpdate</a>();                        <span class="comment">/* Get Core Clock Frequency */</span></div>
<div class="line">  <a class="code hl_function" href="group__SysTick__gr.html#gabe47de40e9b0ad465b752297a9d9f427">SysTick_Config</a>(<a class="code hl_variable" href="group__system__init__gr.html#gaa3cd3e43291e81e795d642b79b6088e6">SystemCoreClock</a> / 1000ul); <span class="comment">/* Setup SysTick Timer for 1 msec */</span></div>
<div class="line">   </div>
<div class="line">  <span class="keywordflow">while</span>(1);</div>
<div class="line">}</div>
<div class="ttc" id="agroup__NVIC__gr_html_gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7"><div class="ttname"><a href="group__NVIC__gr.html#gga7e1129cd8a196f4284d41db3e82ad5c8a6dbff8f8543325f3474cbae2446776e7">SysTick_IRQn</a></div><div class="ttdeci">@ SysTick_IRQn</div><div class="ttdoc">Exception 15: System Tick Interrupt.</div><div class="ttdef"><b>Definition:</b> ref_nvic.txt:398</div></div>
<div class="ttc" id="agroup__compiler__conntrol__gr_html_gab94ebeb20055f1848d7b707d3c7cfc5d"><div class="ttname"><a href="group__compiler__conntrol__gr.html#gab94ebeb20055f1848d7b707d3c7cfc5d">__VECTOR_TABLE</a></div><div class="ttdeci">#define __VECTOR_TABLE</div><div class="ttdoc">Symbol name used for the (static) interrupt vector table.</div><div class="ttdef"><b>Definition:</b> ref_compiler_ctrl.txt:520</div></div>
<div class="ttc" id="agroup__intrinsic__CPU__gr_html_gacb2a8ca6eae1ba4b31161578b720c199"><div class="ttname"><a href="group__intrinsic__CPU__gr.html#gacb2a8ca6eae1ba4b31161578b720c199">__DSB</a></div><div class="ttdeci">void __DSB(void)</div><div class="ttdoc">Data Synchronization Barrier.</div></div>
<div class="ttc" id="agroup__system__init__gr_html_gae0c36a9591fe6e9c45ecb21a794f0f0f"><div class="ttname"><a href="group__system__init__gr.html#gae0c36a9591fe6e9c45ecb21a794f0f0f">SystemCoreClockUpdate</a></div><div class="ttdeci">void SystemCoreClockUpdate(void)</div><div class="ttdoc">Function to update the variable SystemCoreClock.</div></div>
</div><!-- fragment --><h2><a class="anchor" id="using_arm"></a>
Use generic Arm Devices</h2>
<p>Test and example projects of many software components have a need for implementations that are independent from specific device vendors but still have adaptations for various Arm Cortex-M cores to benefit from their architectural differenceis.</p>
<p>The <a href="https://github.com/ARM-software/Cortex_DFP">Cortex_DFP pack</a> provides generic device definitions for standard Arm Cortex-M cores and contains corresponding <a class="el" href="cmsis_device_files.html">CMSIS-Core Device Files</a>. These generic Arm devices can be used as a target for embedded programs, with execution, for example, on processor simulation models.</p>
<p>Validation suits and example projects for such components as <a href="../DSP/index.html">CMSIS-DSP</a>, <a href="../RTOS2/index.html">CMSIS-RTOS</a> and <a href="index.html">CMSIS-Core</a> itself use that approach already.</p>
<h2><a class="anchor" id="using_ARM_Lib_sec"></a>
Create generic libraries</h2>
<p>The CMSIS Processor and Core Peripheral files allow also to create generic libraries. The <a href="../DSP/index.html">CMSIS-DSP libraries</a> are an example for such a generic library.</p>
<p>To build a generic Library set the define <code>__CMSIS_GENERIC</code> and include the relevant <code>core_&lt;cpu&gt;.h</code> CMSIS CPU &amp; Core Access header file for the processor.</p>
<p>The define <code>__CMSIS_GENERIC</code> disables device-dependent features such as the <b>SysTick</b> timer and the <b>Interrupt System</b>.</p>
<p>Refer to <a class="el" href="device_h_pg.html#core_config_sect">Configuration of the Processor and Core Peripherals</a> for a list of the available <code>core_&lt;cpu&gt;.h</code> header files.</p>
<p><b>Example:</b></p>
<p>The following code section shows the usage of the <code>core_&lt;cpu&gt;.h</code> header files to build a generic library for Cortex-M0, Cortex-M3, Cortex-M4, or Cortex-M7 devices.</p>
<p>To select the processor, the source code uses the defines <code>CORTEX_M7</code>, <code>CORTEX_M4</code>, <code>CORTEX_M3</code>, <code>CORTEX_M0</code>, or <code>CORTEX_M0PLUS</code>. One of these defines needs to be provided on the compiler command line. By using this header file, the source code can access the correct implementations for <a class="el" href="group__Core__Register__gr.html">Core Register Access</a>, <a class="el" href="group__intrinsic__CPU__gr.html">Intrinsic Functions for CPU Instructions</a>, <a class="el" href="group__intrinsic__SIMD__gr.html">Intrinsic Functions for SIMD Instructions</a>, and <a class="el" href="group__ITM__Debug__gr.html">Debug Access</a>.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define __CMSIS_GENERIC              </span><span class="comment">/* disable NVIC and Systick functions */</span><span class="preprocessor"></span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#if defined (CORTEX_M7)</span></div>
<div class="line"><span class="preprocessor">  #include &quot;core_cm7.h&quot;</span></div>
<div class="line"><span class="preprocessor">#elif defined (CORTEX_M4)</span></div>
<div class="line"><span class="preprocessor">  #include &quot;core_cm4.h&quot;</span></div>
<div class="line"><span class="preprocessor">#elif defined (CORTEX_M3)</span></div>
<div class="line"><span class="preprocessor">  #include &quot;core_cm3.h&quot;</span></div>
<div class="line"><span class="preprocessor">#elif defined (CORTEX_M0)</span></div>
<div class="line"><span class="preprocessor">  #include &quot;core_cm0.h&quot;</span></div>
<div class="line"><span class="preprocessor">#elif defined (CORTEX_M0PLUS)</span></div>
<div class="line"><span class="preprocessor">  #include &quot;core_cm0plus.h&quot;</span></div>
<div class="line"><span class="preprocessor">#else</span></div>
<div class="line"><span class="preprocessor">  #error &quot;Processor not specified or unsupported.&quot;</span></div>
<div class="line"><span class="preprocessor">#endif</span></div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">
      <script type="text/javascript">
        <!--
        writeFooter.call(this);
        //-->
      </script> 
    </li>
  </ul>
</div>
</body>
</html>
